<?php
/**
 * @package Admin_Form
 * @author Henrique Droog <henridroog@gmail.com>
 * @name Admin_Form_UserForm
 * @since 18/04/2011
 * @version 1.0
 */
class Admin_Form_UserForm extends Zend_Form{
    public function init(){

        $id = new Zend_Form_Element_Hidden('id');

        // Add an text element
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel('Nome')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->addValidator('StringLength',false,array(0,75));

        // Add an password element
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel('Senha')
                ->setRequired(true)
                ->addFilter('StringTrim')
                ->addValidator('NotEmpty')
                ->addValidator('StringLength',false,array(0,25));

        // Add an email element
        $roles = new Admin_Model_RoleMapper();
        $combo = $roles->fetchAll();

        $comboRole = array();
        foreach ($combo as $c){
            $comboRole[$c->id] = $c->name;
        }

        $role = new Zend_Form_Element_Select('role');
        $role->setLabel('Grupo')
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->setMultiOptions($comboRole);

        // Add an email element
        $options = array('true'=>'Sim','false'=>'Não');
        $ativo = new Zend_Form_Element_Select('ativo');
        $ativo->setLabel('Ativo')
                ->setRequired(true)
                ->addValidator('NotEmpty')
                ->setMultiOptions($options);

        // Add the submit button
        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Enviar')
                ->setAttrib('ignore',true);


        $this->addElements( array($id,$name,$password,$role,$ativo,$submit) );
    }
}